package cn.com.czpb.client.module.personal.acticity;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.TextView;

import cn.com.czpb.client.R;
import cn.com.czpb.client.app.ToolBarActivityWhite;
import cn.com.czpb.client.module.personal.adapter.MessageFragmentAdapter;
import cn.com.czpb.client.module.personal.fragment.MessageFragment;
import cn.com.czpb.client.module.personal.fragment.NotifyFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

public class MessageActivity extends ToolBarActivityWhite {
    @BindView(R.id.tablayout_message)
    TabLayout tablayout_message;
    @BindView(R.id.vp_message)
    ViewPager vp_message;
    @BindView(R.id.title_toolbar)
    TextView title_toolbar;
    MessageFragmentAdapter adapter;
    private List<Fragment> list;
    TextView tv_1, tv_2,tv_3;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        init();
        title_toolbar.setText("消息通知");    }

    public void init() {
        list = new ArrayList<>();
        adapter = new MessageFragmentAdapter(getSupportFragmentManager(), list, activity);
        vp_message.setAdapter(adapter);
        tablayout_message.setSelectedTabIndicatorColor(getResources().getColor(R.color.color_df3031));
//        tablayout_message.setupWithViewPager(vp_message);

//        tablayout_message.setTabMode(TabLayout.MODE_FIXED);

        MessageFragment messageFragment = MessageFragment.newInstance();
        NotifyFragment notifyFragment = NotifyFragment.newInstance();
        list.add(messageFragment);
        list.add(notifyFragment);
//
//

        tablayout_message.setupWithViewPager(vp_message);
//
        TabLayout.Tab tab = tablayout_message.getTabAt(0);
        tab.setCustomView(adapter.getTabView(0));
        View tabView = (View) tab.getCustomView().getParent();
        tv_1 = tabView.findViewById(R.id.comment_mine);
        final TabLayout.Tab tab1 = tablayout_message.getTabAt(1);
        tab1.setCustomView(adapter.getTabView(1));
        View tabView1 = (View) tab1.getCustomView().getParent();
        tv_2 = tabView1.findViewById(R.id.notify);
        tv_3 = tabView1.findViewById(R.id.comment_number_tx);

        vp_message.setCurrentItem(0);
        tablayout_message.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
            @Override
            public void onTabSelected(TabLayout.Tab tab) {
                switch (tab.getPosition()) {
                    case 0:
                        tv_1.setTextColor(getResources().getColor(R.color.color_df3031));

                        break;

                    case 1:
                        tv_2.setTextColor(getResources().getColor(R.color.color_df3031));
                        tv_3.setVisibility(View.GONE);
                        break;
                }
            }

            @Override
            public void onTabUnselected(TabLayout.Tab tab) {
                switch (tab.getPosition()) {
                    case 0:

                        tv_1.setTextColor(getResources().getColor(R.color.color_666666));
                        break;

                    case 1:
                        tv_2.setTextColor(getResources().getColor(R.color.color_666666));
                        break;
                }
            }

            @Override
            public void onTabReselected(TabLayout.Tab tab) {

            }
        });
    }

    @Override
    public int setMyContentView() {
        return R.layout.activity_message;
    }

}
